<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Custom initial track selection example</title>

    <script src="../../dist/modern/umd/dash.all.debug.js"></script>

    <!-- Bootstrap core CSS -->
    <link href="../lib/bootstrap/bootstrap.min.css" rel="stylesheet">
    <link href="../lib/main.css" rel="stylesheet">

    <style>
        video {
            width: 640px;
            height: 360px;
        }
    </style>

    <script class="code">
        function init() {

            var video,
                player,
                url = 'https://storage.googleapis.com/shaka-demo-assets/angel-one-widevine/dash.mpd';

            var getTrackWithLowestBitrate = function (trackArr) {
                let min = Infinity;
                let result = [];
                let tmp;

                trackArr.forEach(function (track) {
                    tmp = Math.min.apply(Math, track.bitrateList.map(function (obj) {
                        return obj.bandwidth;
                    }));

                    if (tmp < min) {
                        min = tmp;
                        result = [track];
                    }
                });

                return result;
            }

            video = document.querySelector('video');
            player = dashjs.MediaPlayer().create();

            player.setProtectionData({
                'com.widevine.alpha': {
                    'serverURL': 'https://cwip-shaka-proxy.appspot.com/no_auth'
                }
            })
            player.initialize(video, url, true);
            player.setCustomInitialTrackSelectionFunction(getTrackWithLowestBitrate);

        }
    </script>
</head>
<body>

<main>
    <div class="container py-4">
        <header class="pb-3 mb-4 border-bottom">
            <img class=""
                 src="../lib/img/dashjs-logo.png"
                 width="200">
        </header>
        <div class="row">
            <div class="col-md-4">
                <div class="h-100 p-5 bg-light border rounded-3">
                    <h3>Custom initial track selection example</h3>
                    <p>This sample shows how to define your own initial track selection function. This can be useful to
                        select a specific AdaptationSet with a specific, desired codec.</p>
                </div>
            </div>
            <div class="col-md-8">
                <video controls="true"></video>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <div id="code-output"></div>
            </div>
        </div>
        <footer class="pt-3 mt-4 text-muted border-top">
            &copy; DASH-IF
        </footer>
    </div>
</main>


<script>
    document.addEventListener('DOMContentLoaded', function () {
        init();
    });
</script>
<script src="../highlighter.js"></script>
</body>
</html>
